package implementation;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import utils.XPathQuery;

public class Situation {

	private String nom;
	private String question;
	private List<String> reponses;
	private XPathQuery xpath;

	public Situation() {
		initializeXpath();
	}

	public Situation(String nom, String question, List<String> reponses) {
		initializeXpath();
		this.nom = nom;
		this.question = question;
		this.reponses = reponses;
	}

	public Situation(Node nom, Node question, Node reponses) {
		initializeXpath();
		setNom(nom);
		setQuestion(question);
		setReponses(reponses);
	}

	private void initializeXpath() {
		xpath = new XPathQuery();
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public void setNom(Node nom) {
		this.nom = xpath.query(nom, "text()").item(0).getNodeValue();
	}

	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public void setQuestion(Node question) {
		this.question = xpath.query(question, "text()").item(0).getNodeValue();
	}

	public List<String> getReponses() {
		return reponses;
	}

	public void setReponses(List<String> reponses) {
		this.reponses = reponses;
	}

	public void setReponses(Node reponses) {
		NodeList list = reponses.getChildNodes();
		List<String> inter = new ArrayList<String>();
		for (int i = 0; i < list.getLength(); i++) {
			inter.add(xpath.query(list.item(i), "text()").item(0)
					.getNodeValue());
		}

		this.reponses = inter;
	}

}
